package com.wits.platform.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.wits.platform.dao.custom.SysTabDDaoCustom;
import com.wits.platform.entity.SysTabD;
import com.wits.platform.entity.SysTabDPK;

@Component
public class SysTabDDaoImpl extends BaseDaoImpl<SysTabD,SysTabDPK> implements SysTabDDaoCustom {
	
	private static String SQL_SELECT_ENABLED="select d.* from wits_systab_d d inner join wits_systab_h h on(d.th_id=h.th_id) where h.th_id=:thId and h.is_Enable='T' and d.is_Enable='T'";
	
	private static String SQL_SELECT_ENABLED_BY_LOCALE="select d.* from wits_systab_d d inner join wits_systab_h h on(d.th_id=h.th_id) where h.th_id=:thId and d.lang_type=:langType and h.is_Enable='T' and d.is_Enable='T'";
	
	@Override
	@SuppressWarnings("unchecked")
	public List<SysTabD> findEnabled(String thId) {
		return em.createNativeQuery(SQL_SELECT_ENABLED,SysTabD.class).setParameter("thId", thId).getResultList();
	}


	@SuppressWarnings("unchecked")
	@Override
	public List<SysTabD> findEnabledByLangType(String thId, String langType) {
		return em.createNativeQuery(SQL_SELECT_ENABLED_BY_LOCALE,SysTabD.class).setParameter("thId", thId).setParameter("langType", langType).getResultList();
	}


	@Override
	public List<SysTabD> findTabDByThId(String thId) {
		return this.find(SysTabD.class, "from SysTabD where id.thId=?1",thId);
	}

}
